package com.qf.service;

import com.qf.config.IdWorker;
import com.qf.constant.CacheConstants;
import com.qf.constant.RabbitMQConstants;
import com.qf.constant.ReportStateConstants;
import com.qf.constant.SourceType;
import com.qf.feign.CacheFeign;
import com.qf.model.StandardSubmit;
import com.qf.pojo.SmsInterfaceForm;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zwnan
 */
@Service
public class SmsInterfaceServiceImpl implements SmsInterfaceService{


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private IdWorker idWorker;

    @Override
    public void sendMessage(SmsInterfaceForm smsInterfaceForm) {

        StandardSubmit standardSubmit = new StandardSubmit();
        standardSubmit.setClientID(Integer.valueOf(smsInterfaceForm.getClientID()));
        standardSubmit.setSrcSequenceId(Long.valueOf(smsInterfaceForm.getSrcID()));
        standardSubmit.setMessageContent(smsInterfaceForm.getContent());
        standardSubmit.setReportState(ReportStateConstants.WAIT);
        standardSubmit.setSource(SourceType.HTTP);

        String mobile = smsInterfaceForm.getMobile();
        String[] m = mobile.split(",");
        for (String s : m) {
            long id = idWorker.nextId();
            standardSubmit.setSequenceId(String.valueOf(id));
            standardSubmit.setDestMobile(s);
            rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_PRE_SEND+"_exchange","routingKey", standardSubmit);
        }


    }
}
